package meituan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while((str=br.readLine())!=null){
            String[] arr1 = str.split(" ");
            int n = Integer.parseInt(arr1[0]);
            int m = Integer.parseInt(arr1[1]);
            int k =Integer.parseInt(arr1[2]);
            long sum1 = 0,sum2 = 0;
            String[] arr = new String[2];
            while(n>0){
                arr = br.readLine().split(" ");
                long x = Integer.parseInt(arr[0]);
                long y = Integer.parseInt(arr[1]);
                sum1 = (y>=k)? sum1+x*y:sum1;
                n--;
            }
            while(m>0){
                arr = br.readLine().split(" ");
                long x = Integer.parseInt(arr[0]);
                long y = Integer.parseInt(arr[1]);
                sum2 = (y>=k)?sum2+x*y:sum2;
                m--;
            }
            System.out.println(sum1+" "+sum2);
            if(sum1>sum2){
                System.out.println("A");
            }else{
                System.out.println("B");
            }
        }
    }
}
